/// 
/// Author: Jeff Liu
/// Date: 2023-05-05 16:46:15
/// LastEditTime: 2023-05-08 13:37:12
/// LastEditors: Jeff Liu
/// Description: 
/// FilePath: /HCCBJ/src/HCC/SVR/Prod/BP/SubscribeAndPublishGeneral.cls
/// Jeff.liu@intersytems.com
/// 
Class HCC.SVR.Prod.BP.SubscribeAndPublishGeneral Extends Ens.BusinessProcessBPL [ DependsOn = HCC.SVR.Prod.BP.Context ]
{


/// BPL Definition
XData BPL [ XMLNamespace = "http://www.intersystems.com/bpl" ]
{
<process language='objectscript' request='HCC.SVR.Prod.MSG.SVRRequest' response='HCC.SVR.Prod.MSG.SVRResponse' contextsuperclass='HCC.SVR.Prod.BP.Context' height='2700' width='2000' >
<context>
<property name='SubscriptionIDLIst' type='%Integer' collection='list' instantiate='0' />
<property name='k1' type='%Integer' initialexpression='1' instantiate='0' />
<property name='Target' type='%String' instantiate='0' >
<parameters>
<parameter name='MAXLEN'  value='50' />
</parameters>
</property>
<property name='Source' type='%String' instantiate='0' >
<parameters>
<parameter name='MAXLEN'  value='50' />
</parameters>
</property>
<property name='Iterator' type='%Integer' initialexpression='1' instantiate='0' />
<property name='EventName' type='%String' instantiate='0' >
<parameters>
<parameter name='MAXLEN'  value='50' />
</parameters>
</property>
<property name='tResponse' type='HCC.SVR.Prod.MSG.SVRResponse' instantiate='0' />
<property name='SubID' type='%Integer' instantiate='0' />
<property name='IsSync' type='%Boolean' instantiate='0' />
<property name='ErrMsg' type='%String' instantiate='0' >
<parameters>
<parameter name='MAXLEN'  value='2500' />
</parameters>
</property>
<property name='Topic' type='%String' instantiate='0' >
<parameters>
<parameter name='MAXLEN'  value='50' />
</parameters>
</property>
<property name='SubscriberName' type='%String' instantiate='0' >
<parameters>
<parameter name='MAXLEN'  value='50' />
</parameters>
</property>
<property name='Info' type='%String' instantiate='0' >
<parameters>
<parameter name='MAXLEN'  value='2500' />
</parameters>
</property>
</context>
<sequence xend='200' yend='1900' >
<scope xpos='200' ypos='250' xend='200' yend='1800' >
<code name='获取sync 超时时间' xpos='200' ypos='350' >
<![CDATA[ set context.TimeOutSeconds =##class(Ens.Director).GetHostSettingValue(context.pProductionName_"||HCC.SVR.Prod.BP.MainControlGeneral","SyncTimeOutSeconds",.tSC)]]>
</code>
<trace name='追踪同步超时时间' value='"========"_context.TimeOutSeconds' xpos='200' ypos='450' />
<assign name="设定订阅topic" property="context.EventName" value="request.Action" action="set" xpos='200' ypos='550' >
<annotation><![CDATA[根据请求消息的Action]]></annotation>
</assign>
<code name='获取订阅列表' xpos='200' ypos='650' >
<![CDATA[ set context.SubscriptionIDLIst =##class(HCC.SVR.PubSub.Subscription).GetSubscribtionByTopic(context.EventName)]]>
</code>
<if name='判断是否有订户' condition='context.SubscriptionIDLIst.Count()=0' xpos='200' ypos='750' xend='200' yend='1000' >
<true>
<code name='业务未实现，没有订户' xpos='470' ypos='900' >
<![CDATA[ set context.tResponse= ##class(HCC.Utils.ResponseHelper).ReturnErrorMsgNoSenderInfo(request.MsgId,"异常服务代码，系统未实现该业务流程,没有订阅方.")]]>
</code>
</true>
<false>
<foreach name='发送请求消息到订阅者' property='context.SubscriptionIDLIst' key='context.Iterator' xpos='200' ypos='900' xend='200' yend='1400' >
<annotation><![CDATA[根据订阅列表发送消息到目标处理过程]]></annotation>
<assign name="取出SubID" property="context.SubID" value="context.SubscriptionIDLIst.GetAt(context.Iterator)" action="set" xpos='200' ypos='250' />
<assign name="取出Topic" property="context.Topic" value="##class(HCC.SVR.PubSub.Subscription).%OpenId(context.SubID).Topic.TopicName" action="set" xpos='200' ypos='350' />
<assign name="取出订阅者名字" property="context.SubscriberName" value="##class(HCC.SVR.PubSub.Subscription).%OpenId(context.SubID).Subscriber.SubscriberName" action="set" xpos='200' ypos='450' />
<trace name='追踪订阅' value='context.Topic_":"_context.SubscriberName' xpos='200' ypos='550' />
<assign name="取出Target" property="context.Target" value="##class(HCC.SVR.PubSub.Subscription).%OpenId(context.SubID).Subscriber.Target" action="set" xpos='200' ypos='650' />
<assign name="取出是否为同步发送" property="context.IsSync" value="##class(HCC.SVR.PubSub.Subscription).%OpenId(context.SubID).IsSync" action="set" xpos='200' ypos='750' />
<trace name='追踪 iterator 和target' value='context.Iterator_"-------"_context.Target' xpos='200' ypos='850' />
<if name='判断发送方式' condition='context.IsSync' xpos='200' ypos='950' xend='200' yend='1300' >
<true>
<call name='同步订阅者' target='@context.Target' async='1' xpos='200' ypos='1100' >
<request type='HCC.SVR.Prod.MSG.SVRRequest' >
<assign property="callrequest" value="request" action="set" />
</request>
<response type='HCC.SVR.Prod.MSG.SVRResponse' >
<assign property="context.tResponse" value="callresponse" action="set" />
</response>
</call>
</true>
<false>
<call name='异步订阅者' target='@context.Target' async='1' xpos='470' ypos='1100' >
<request type='HCC.SVR.Prod.MSG.SVRRequest' >
<assign property="callrequest" value="request" action="set" />
</request>
<response type='HCC.SVR.Prod.MSG.SVRResponse' >
<assign property="response" value="callresponse" action="set" />
</response>
</call>
<code name='返回异步成功消息' xpos='470' ypos='1200' >
<![CDATA[ set context.tResponse= ##class(HCC.Utils.ResponseHelper).ReturnSuccessMsgNoSenderInfo(request.MsgId,"交互服务异步发送处理成功")]]>
</code>
</false>
</if>
</foreach>
</false>
</if>
<sync name='sync 返回消息' calls='同步订阅者' timeout='context.TimeOutSeconds' type='any' xpos='200' ypos='1100' />
<if name='追踪超时' condition='synctimedout =0' xpos='200' ypos='1200' xend='200' yend='1450' >
<false>
<code name='返回超时消息' xpos='335' ypos='1350' >
<![CDATA[ set context.tResponse= ##class(HCC.Utils.ResponseHelper).ReturnErrorMsgNoSenderInfo(request.MsgId,"消息处理超时"_$char(10)_context.ErrMsg)]]>
</code>
</false>
</if>
<assign name="返回消息" property="response" value="context.tResponse" action="set" xpos='200' ypos='1550' />
<faulthandlers>
<catchall xpos='200' ypos='1650' xend='200' yend='550' >
<trace value='"%LastError "_ $System.Status.GetErrorCodes(..%Context.%LastError)_ " : "_ $System.Status.GetOneStatusText(..%Context.%LastError)' xpos='200' ypos='250' />
<code xpos='200' ypos='350' >
<![CDATA[ set context.tResponse= ##class(HCC.Utils.ResponseHelper).ReturnErrorMsgNoSenderInfo(request.MsgId,"平台内部异常."_ $System.Status.GetErrorCodes(..%Context.%LastError)_ " : "_ $System.Status.GetOneStatusText(..%Context.%LastError))]]>
</code>
<assign property="response" value="context.tResponse" action="set" xpos='200' ypos='450' />
</catchall>
</faulthandlers>
</scope>
</sequence>
</process>
}

}
